﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.04.18
 * 描 述：地区选择
 */
var acceptClick;
var dfopid = request('dfopid');
var selectValue = request("selectValue");
var provinceName = '';
var cityName = '';
var countyName = '';

var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.bind();
            page.initData();
        },
        bind: function () {
            // 省市区
            $('#area').lrAreaSelect();
        },
        initData: function () {
            if (!!selectValue) {
                var arr = selectValue.split("_");
                var provinceId = arr[0];
                var cityId = arr[1];
                var countyId = arr[2];

                $("#provinceId").lrselectSet(provinceId);
                if(!!cityId) {
                    $("#cityId").lrselectSet(cityId);
                }
                if(!!countyId) {
                    $("#countyId").lrselectSet(countyId);
                }
            }
        }
    };
    // 保存数据
    acceptClick = function (callBack) {
        if (!$('#form').lrValidform()) {
            return false;
        }
        var formData = $('#form').lrGetFormData();

        var selectId = formData.provinceId + "," + formData.cityId + "," + formData.countyId;
        if (!!formData.provinceId) {
            provinceName = $("#provinceId").children("div").html();
        } else {
            return false;
        }
        var selectText = provinceName;
        if (!!formData.cityId) {
            cityName = $("#cityId").children("div").html();
            selectText = selectText + "_" + cityName;
        }
        if (!!formData.countyId) {
            countyName = $("#countyId").children("div").html();
            selectText = selectText + "_" + countyName;
        }
        var postitem = {value: selectId, text: selectText};
        callBack(postitem, dfopid);
        return true;
    };
    page.init();
}